package com.prasad.java;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Test;

public class Person {
	
	private String name;
	private String sex;
	
	Person(){
		
	}
	
	Person(String name, String sex) {
		this.name = name;
		this.sex = sex;
	}
	
	
	@Override
	public boolean equals(Object obj) {
		Person p = (Person)obj;
		if(p == null)
			return false;
		if(this.name == p.name && this.sex == p.sex)
			return true;
		else
			return false;
	}
	
	@Override
	public int hashCode() {
		int hash = 2;
		hash = 2*hash + this.name.hashCode();
		hash = 2*hash + this.sex.hashCode();
				
		return hash;
	}

	public int compareTo(Person p2) {
		return this.name.compareToIgnoreCase(p2.name);
	}
	
	@Test
	public void testPerson() {
		
		List<String> list = new ArrayList<String>();
		 
		 list.add("Sreedhar");
		 list.add("prasad");
		 list.add("Ali");
		 list.add("Prasad");
		 list.add("sreedhar");
		 list.add("ali");
		 
		 Collections.sort(list);
		 
		 Assert.assertThat(list.get(0), CoreMatchers.is("ali"));
	}
	
}
